package com.lins.wechat.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author linshuo
 * @Date 2023/7/26 17:08
 */
@Component
public class RedisUtils {

    @Autowired
    RedisTemplate<String,String> redis;

    public static RedisTemplate<String,String> redisTemplate;

    @PostConstruct
    public void getRedisTemplate(){
        redisTemplate = this.redis;
    }

    public String get(String k){
        return redisTemplate.opsForValue().get(k);
    }
    public void set(String k,String v){
        redisTemplate.opsForValue().set(k,v);
    }

    //以哈希类型的格式进行存取
    public Object hget(String k,String h){
        return redisTemplate.opsForHash().get(k,h);
    }
    public void hset(String k,String h,String v){
        redisTemplate.opsForHash().put(k,h,v);
    }

    public RedisUtils() {
    }
}
